package com.three.sb_group3.service.impl;

import com.three.sb_group3.entity.Movies;
import com.three.sb_group3.entity.Users;
import com.three.sb_group3.mapper.MoviesMapper;
import com.three.sb_group3.service.MoviesService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

@Service

public class MoviesServiceimpl implements MoviesService {

    @Resource
    private MoviesMapper moviesMapper;
    @Override
    public List<Movies> moviesList() {
        List<Movies> movies = moviesMapper.selectList(  null);
        return movies ;
    }

    @Override
    public List<Movies> moviesAdmin() {
        Movies movies = new Movies();
        movies.setMovieName("spiderman-2");
        movies.setDirector("sam.1");
        movies.setGenre("Crime, action, thriller, science fiction");
        movies.setDescription("Middle school student Peter Parker (played by Tobey Maguire) lost both parents at a young age and lives with his beloved uncle and aunt in Queens, New York, living an ordinary student life. Like many children from broken families in the United States, although Peter is smart, he is shy and often ridiculed by some classmates. Apart from Harry Osborne (played by James Franco), who is even more cowardly than him, Peter has no friends. However, Peter has always had a special fondness for the neighbor's girl Mary (played by Kirsten Dunst). But Harry Osborne, like him, also fell in love with Mary.");
        movies.setMainActors("Tobey Maguire,Kirsten Dunst");
        movies.setReleaseDate("20020502");
        int insert = moviesMapper.insert(movies);
        System.out.println(insert);
        return  null;
    }

    @Override
    public List<Movies> moviesLikes() {
        Movies movies = new Movies();
        movies.setId(1L);
        movies.setLikes(2);
        int insert = moviesMapper.updateById(movies);
        System.out.println(insert);
        return null;
    }

    @Override
    public List<Movies> moviesEdit() {
        Movies movies = new Movies();
        movies.setId(4L);
        movies.setReleaseDate("20020502");
        int insert = moviesMapper.updateById(movies);
        System.out.println(insert);
        return  null;
    }

    @Override
    public List<Movies> moviesComments() {
        Movies movies = new Movies();
        movies.setId(3L);
        movies.setComments("its nice movie");
        int insert = moviesMapper.updateById(movies);
        System.out.println(insert);
        return null;
    }

    @Override
    public List<Movies> moviesDelete() {
        Movies movies = new Movies();
        movies.setId(2L);
        int delete = moviesMapper.deleteById(2L);
        System.out.println(delete);
        return  null;
    }

    @Override
    public List<Movies> moviesSearch() {
        HashMap<String,Object> map = new HashMap<>();
       // map.put("likes","1");
        // map.put("genre","thriller");
        map.put("release_date","20020502");
        List<Movies> movies = moviesMapper.selectByMap(map);
        movies.forEach(System.out::println);
        return  movies;
    }
}
